package com.hamster.crm.service.impl;

import com.hamster.crm.mapper.BranchProfitConfigMapper;
import com.hamster.crm.pojo.BranchProfitConfig;
import com.hamster.crm.service.BranchProfitConfigService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;

/**
 * 分公司返利设置的 Service
 * @author Tarry
 * @create 2019/12/20 11:07
 */
@Service
public class BranchProfitConfigServiceImpl implements BranchProfitConfigService {
    @Autowired
    private BranchProfitConfigMapper branchProfitConfigMapper;

    /**
     * 获取分公司返利明细
     * @return BranchProfitConfig
     */
    @Override
    public BranchProfitConfig get() {
        BranchProfitConfig branchProfitConfig = branchProfitConfigMapper.selectById("1");
        return branchProfitConfig;
    }

    /**
     * 新增或修改，分公司返利明细
     * @param branchProfitConfig
     */
    @Override
    public void insert(BranchProfitConfig branchProfitConfig) {
        //如果明细记录存在，则修改，不存在则新增
        branchProfitConfig.setId("1");
        branchProfitConfig.setDel("0");
        branchProfitConfig.setInputTime(new Date());
        branchProfitConfig.setInputUser("功能待完善...");
        if (branchProfitConfigMapper.selectById("1") == null){
            branchProfitConfigMapper.insert(branchProfitConfig);
        }else {
            branchProfitConfigMapper.updateById(branchProfitConfig);
        }
    }
}
